package cn.stronglink.asset.module.patrol.controller;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.plugins.Page;
import cn.stronglink.asset.model.Patrol;
import cn.stronglink.asset.module.patrol.service.PatrolService;
import cn.stronglink.suite.core.base.AbstractController;
import cn.stronglink.suite.core.log.annotation.OperateLog;
import cn.stronglink.suite.core.log.annotation.OperateLog.OpType;

@Controller
@RequestMapping(value = "patrol")
public class PatrolController extends AbstractController {

	@Autowired
	private PatrolService patrolService;

	/**
	 * 查询所有巡检并分页
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param params
	 * @return
	 */
	@RequestMapping(value = "queryList")
	public ResponseEntity<ModelMap> queryList(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Map<String, Object> params) {	
		@SuppressWarnings("unchecked")
		Page<Patrol> page = (Page<Patrol>) super.getPage(params);
		Page<Patrol> data = patrolService.queryList(page,params);
		return setSuccessModelMap(modelMap, data);
	}
	
	/**
	 * 根据巡检单Id查询巡检明细
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "qryById")
	public ResponseEntity<ModelMap> qryById(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Long id) {	
		Patrol data =patrolService.qryById(id);
		return setSuccessModelMap(modelMap, data);
	}
	
	/**
	 * 创建巡检单
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param inventory
	 * @return
	 */
	@OperateLog(module = "巡检单管理",desc="创建巡检单", type = OpType.ADD)
	@RequestMapping(value = "create")
	public ResponseEntity<ModelMap> create(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Patrol inspection) {
		patrolService.create(inspection);
		return setSuccessModelMap(modelMap, null);
	}
	
	/**
	 * 编辑巡检单
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param inventory
	 * @return
	 */
	@OperateLog(module = "巡检单管理",desc="修改巡检单", type = OpType.UPDATE)
	@RequestMapping(value = "edit")
	public ResponseEntity<ModelMap> edit(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Patrol inspection) {
		patrolService.edit(inspection);
		return setSuccessModelMap(modelMap, null);
	}
	/**
	 * 删除巡检单
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param id
	 * @return
	 */
	@OperateLog(module = "巡检单管理",desc="删除巡检单", type = OpType.DEL)
	@RequestMapping(value = "remove")
	public ResponseEntity<ModelMap> remove(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Long id) {
		patrolService.remove(id);
		return setSuccessModelMap(modelMap, null);
	}
	/**
	 * 根据计划详情id获取巡检单列表
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "qryPatrolList")
	public ResponseEntity<ModelMap> qryPatrolList(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Map<String,Object> params) {
		@SuppressWarnings("unchecked")
		Page<Patrol> page = (Page<Patrol>) super.getPage(params);
		Page<Patrol> data = patrolService.qryPatrolList(page,params);
		return setSuccessModelMap(modelMap, data);
	}
	
	/**
	 * 通过巡检id查询巡检项详情列表
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param params
	 * @return
	 */
	@RequestMapping(value="queryPatrolItems")
	public ResponseEntity<ModelMap> queryDetailsList(ModelMap modelMap,HttpServletRequest request,
			HttpServletResponse response,@RequestBody Map<String,Object> params){
		@SuppressWarnings("unchecked")
		Page<HashMap> page = (Page<HashMap>) super.getPage(params);
		Page<HashMap> data = patrolService.queryPatrolItemsList(page,params);
		return setSuccessModelMap(modelMap,data);
	}
}
